package com.itheima.mall.api.pms;


import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mall.mapper.pms.PmsProductAttributeMapper;
import com.itheima.mall.pojo.pms.ProductAttribute;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;


@DubboService
public class PmsProductAttributeServiceApiImpl implements PmsProductAttributeServiceApi {
    @Autowired
    private PmsProductAttributeMapper pmsProductAttributeMapper;

    //添加商品属性信息
    @Override
    public void create(ProductAttribute productAttribute) {
        pmsProductAttributeMapper.insert(productAttribute);
    }

    //批量删除商品属性
    @Override
    public void delete(Long[] ids) {
        pmsProductAttributeMapper.deleteBatchIds(Arrays.asList(ids));
    }

    //修改商品属性信息
    @Override
    public void update(ProductAttribute productAttribute) {
        pmsProductAttributeMapper.updateById(productAttribute);
    }

    //查询单个商品属性
    @Override
    public ProductAttribute getById(Integer id) {
        Long pid = Convert.toLong(id);
        LambdaQueryWrapper<ProductAttribute>wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(ProductAttribute::getId,pid);
        return pmsProductAttributeMapper.selectOne(wrapper);
    }
}
